<?php
header('Content-Type: text/html; charset=utf-8');
include_once ('../connexpdo.php'); // pour inclure nos classes
global $connexion;
$desktop=array();
$mobile=array();
$mobileHD=array();
if($_POST['type']=="expiration"){
	$now = date ( 'Y-m-d' );
	$Ym= date ( 'Ym', mktime ( 0, 0, 0, date ( 'm' ), date ( 'd' ), date ( 'Y' ) ) );
	$queryCheckDesktop="SELECT l.idpraticien, p.nom, p.prenom FROM licences l INNER JOIN praticiens p ON p.id=l.idpraticien WHERE l.date_fin<'".$now."' AND l.idlicence_type LIKE '1%' ;";
	$queryCheckMobile="SELECT l.idpraticien, p.nom, p.prenom FROM licences l INNER JOIN praticiens p ON p.id=l.idpraticien WHERE l.date_fin<'".$now."' AND l.idlicence_type LIKE '2%' ;";
	$queryCheckMobileHD="SELECT l.idpraticien, p.nom, p.prenom FROM licences l INNER JOIN praticiens p ON p.id=l.idpraticien WHERE l.date_fin<'".$now."' AND l.idlicence_type LIKE '3%' ;";
	$querycron="SELECT dateMAJ FROM gestsmsclients where EXTRACT(YEAR_MONTH FROM MoisConcerne)='".$Ym."' GROUP BY dateMAJ;";
	$dataDesktop= $connexion->query($queryCheckDesktop);
	$dataMobile= $connexion->query($queryCheckMobile);
	$dataMobileHD=$connexion->query($queryCheckMobileHD);
	$MAJCron=$connexion->query($querycron);
	while($row= $dataDesktop->fetch(PDO::FETCH_OBJ)){
		array_push($desktop, array("praticien"=>$row->idpraticien,"nom"=>$row->nom, "prenom"=>$row->prenom));
	}
	while($row= $dataMobile->fetch(PDO::FETCH_OBJ)){
		array_push($mobile, array("praticien"=>$row->idpraticien,"nom"=>$row->nom, "prenom"=>$row->prenom));
	}
	while($row= $dataMobileHD->fetch(PDO::FETCH_OBJ)){
		array_push($mobileHD, array("praticien"=>$row->idpraticien,"nom"=>$row->nom, "prenom"=>$row->prenom));
	}
	$datemajcron= $MAJCron->fetch()['dateMAJ'];
}
$vretour=array("desktop"=>$desktop, "mobile"=>$mobile, "mobileHD"=>$mobileHD, "DateMAJCron"=>$datemajcron);
echo json_encode($vretour);
?>